package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.itcast.crm.domain.Customer;

public interface CustomerDao extends JpaSpecificationExecutor<Customer>, JpaRepository<Customer, Integer> {
   // 查询没有绑定定区的客户
	public List<Customer> findByFixedAreaIdIsNull();


	@Query("update Customer set fixedAreaId=? where id=?")
	@Modifying // 修改数据库需要添加这个注解
	public void associateCustomerToFixedArea(String fixedAreaId, int parseInt);

    @Query("update Customer set fixedAreaId=null where fixedAreaId=? ")
    //做修改的jpql语句必须要有modifing注解
    @Modifying
	public void clearAssociatedCustomer(String fixedAreaId);

    //查询绑定某个定区的客户
	public List<Customer> findCustomerByfixedAreaId(String fixedAreaId);

    //根据客户电话查询客户信息，规则命名法
	public Customer findByTelephone(String telephone);

    @Query("update Customer set type=1 where telephone=?")
    @Modifying//数据库的增删改需要添加modifing
	public void updateType(String telephone);

    // 根据手机号和密码查询客户信息
	public Customer findCustomerByTelephoneAndPassword(String telephone, String password);
    
	//根据地址查询对应的定区id
	@Query("select fixedAreaId from Customer where address=?")
	public String findFixedAreaIdByAddress(String address);


	

}
